

#import "BaseViewController.h"
#import "IQKeyboardManager.h"
#import "Tool.h"


@interface BaseViewController ()<UIGestureRecognizerDelegate>

@property (nonatomic, strong, readonly) NSArray * textViewArray;

@property (nonatomic, strong) UIView * keyBoard_v;

@property (nonatomic, assign) CGRect  tabbarRec;

@end

@implementation BaseViewController

NSString *GetClassStr(NSArray <NSArray <NSString *> *> * arr , NSIndexPath *indexPath){
    NSArray *arrA = nil;
    if (indexPath.section >= arr.count) {
        arrA = arr.lastObject;
        
    }else{
        arrA = arr[indexPath.section];
    }
    
    
    if (indexPath.row >= arrA.count)
        return arrA[0];
    return arrA[indexPath.row];
}

NSArray <NSString *> * CellArr(NSArray <NSArray <NSString *> *> * arr){
    NSMutableArray *cellArr = [NSMutableArray array];
    [arr enumerateObjectsUsingBlock:^(NSArray<NSString *> * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [obj enumerateObjectsUsingBlock:^(NSString * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            if (![cellArr containsObject:obj]) {
                [cellArr addObject:obj];
            }
        }];
    }];
    return cellArr;
}


-(void)viewDidDisappear:(BOOL)animated{
 
    [self.view endEditing:YES];
       [super viewDidDisappear:animated];
}

-(void)viewWillAppear:(BOOL)animated{

    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:self.hidNav animated:animated];
    
    [[NSNotificationCenter defaultCenter] postNotificationName:LC_CURRENTVC object:self];
   
}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    
}

-(void)dealloc{
   
}

+ (instancetype)hidNavNew{
    BaseViewController *vc = self.new;
    vc.hidNav = YES;
    return vc;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
  
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"fanhui_hei"] style:UIBarButtonItemStylePlain target:self action:@selector(backUpRootView)];
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor blackColor];
    
    
    id target = self.navigationController.interactivePopGestureRecognizer.delegate;
       
       // handleNavigationTransition:为系统私有API,即系统自带侧滑手势的回调方法，我们在自己的手势上直接用它的回调方法
    
       UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:target action:@selector(handleNavigationTransition:)];
    
       panGesture.delegate = self; // 设置手势代理，拦截手势触发
    
       [self.view addGestureRecognizer:panGesture];
       
       // 一定要禁止系统自带的滑动手势
       self.navigationController.interactivePopGestureRecognizer.enabled = NO;
    
    if(@available(iOS 13.0,*)){
        
        UINavigationBarAppearance * appearance=[[UINavigationBarAppearance alloc]init];
//         背景色
        appearance.backgroundColor= [UIColor whiteColor];
//         去除导航栏阴影（如果不设置clear，导航栏底下会有一条阴影线）
//        appearance.shadowColor=[UIColor clearColor];
//         字体颜色、尺寸等
        appearance.titleTextAttributes=@{NSForegroundColorAttributeName:[UIColor blackColor]};
//         带scroll滑动的页面
        self.navigationController.navigationBar.scrollEdgeAppearance=appearance;
//         常规页面
        self.navigationController.navigationBar.standardAppearance=appearance;
        
    }
    
    [self.view frameSelf];

    [self detailUI];
//    [self getData:0];

}


// 什么时候调用，每次触发手势之前都会询问下代理方法，是否触发
// 作用：拦截手势触发
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
    // 当当前控制器是根控制器时，不可以侧滑返回，所以不能使其触发手势
    if(self.navigationController.childViewControllers.count == 1)
    {
        return NO;
    }
    
    return YES;
}


- (void)detailUI{}

- (void)getData:(NSInteger)page{}


- (IBAction)backUpRootView
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)addRightBarItemWithData:(id)data withSEL:(SEL)sel{
    if ([data isKindOfClass:[UIImage class]]) {
         self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[data imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStyleDone target:self action:sel];
       
    }else{
        self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:data style:UIBarButtonItemStylePlain target:self action:sel];
    }
   self.navigationItem.rightBarButtonItem.tintColor = [UIColor blackColor];
}
- (void)addLeftBarItemWithData:(id)data withSEL:(SEL)sel{
    if ([data isKindOfClass:[UIImage class]]) {
        self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[data imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStyleDone target:self action:sel];
    }else{
        self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:data style:UIBarButtonItemStylePlain target:self action:sel];
        self.navigationItem.leftBarButtonItem.tintColor = [UIColor blackColor];
        
        
    }
}

- (void)pushVC:(BaseViewController *)vc{
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController setNavigationBarHidden:vc.hidNav animated:NO];
    [self.navigationController pushViewController:vc animated:YES];
    
}

- (void)setButtonState:(UIButton *)button{
    [self.view layoutIfNeeded];
    button.backgroundColor = UIColorHex(@"D70D02");
    button.layer.cornerRadius = button.height / 2;
    button.layer.shadowColor = UIColorHex(@"D70D02").CGColor;
    button.layer.shadowOpacity = 0.5;
    button.layer.shadowRadius = 5.f;
    button.layer.shadowOffset = CGSizeMake(0,3);
}




@end
